package com.activity;

import com.connection.DatabaseConnection;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends Activity {
	
	TextView unidade;
	TextView disciplina;
	TextView turma;
	TextView bimestre;
	
	Bundle param = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        DatabaseConnection data = new DatabaseConnection(
				getApplicationContext());
		SQLiteDatabase escola = data.getWritableDatabase();	
		escola.close();
		
		unidade = (TextView)findViewById(R.id.escolaTxt);
		disciplina = (TextView)findViewById(R.id.disciplinaTxt);
		turma = (TextView)findViewById(R.id.turmaTxt);
		bimestre = (TextView)findViewById(R.id.bimestreTxt);
		
		Intent it = getIntent();
		if(it != null){
			param = it.getExtras();
			if(param != null){
				unidade.setText(param.getString("unidade"));
				disciplina.setText(param.getString("disciplina"));
				turma.setText(param.getString("turma"));
				bimestre.setText(param.getString("bimestre"));
				
			}
		}
		
    }
    
    public void abre_alterar(View v) {
    	Intent i_alt = new Intent(getApplicationContext(), AlterarActivity.class);
		startActivity(i_alt);
		
	}
    
    public void abre_conteudo(View v) {
    	if(param != null){
	    	Intent i_cont = new Intent(getApplicationContext(), ConteudoActivity.class);
	    	i_cont.putExtras(param);
			startActivity(i_cont);
    	}else{
    		AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);
    		alert.setTitle("Opa!");
    		alert.setMessage("Tem que selecionar a unidade, disciplina, turma e bimestre no topo da tela para ter acesso ao conteudo.");
    		alert.setNeutralButton("OK", null);
    		alert.show();
    	}
	}

//    @Override
//    public boolean onCreateOptionsMenu(Menu menu) {
//        getMenuInflater().inflate(R.menu.activity_main, menu);
//        return true;
//    }
}
